<template>
  <div class="login">
    <el-card class="login-card">
      <div class="clearfix">
        <el-image class="login-image" :src="login_url"></el-image>
        <p class="login-title">登 录</p>
        <p class="login-desc">欢迎登录知乎课堂后台系统</p>
        <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="10px">
          <el-form-item prop="username">
            <el-input v-model="ruleForm.username"  placeholder="请输入管理员账号" class="input"></el-input>
          </el-form-item>
          <el-form-item prop="pass">
            <el-input type="password" v-model="ruleForm.pass"  placeholder="请输入管理员密码" class="input"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="submitForm('ruleForm')">登录</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-card>
    <p class="footer">Copyright © ZhiFou All Rights Reserved</p>
  </div>
</template>

<script>
export default {
  components: {},
  data () {
    var validateUser = (_rule, value, callback) => {
      if (!value) {
        return callback(new Error('用户名不能为空'))
      }
      callback()
    }
    var validatePass = (_rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入密码'))
      } else {
        callback()
      }
    }
    return {
      login_url: require('../assets/img/icon.png'),
      ruleForm: {
        username: '',
        pass: ''
      },
      rules: {
        username: [
          { validator: validateUser, trigger: 'blur' }
        ],
        pass: [
          { validator: validatePass, trigger: 'blur' }
        ]

      }
    }
  },
  created () { },
  mounted () { },
  methods: {
    submitForm (formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          // this.loginLoading = true
          // console.log(11111)
          this.$router.push(
            '/home'
          )
          sessionStorage.setItem('user', this.ruleForm.username)

          // this.$axios
          //   .post('/auth/login', this.form)
          //   .then((res) => {
          //     if (res.data.success) {
          //       sessionStorage.setItem('user', JSON.stringify(res.data.data.user))
          //       sessionStorage.setItem('token', res.data.token)
          //       this.$router.push('/home')
          //     } else {
          //       this.$message.error(res.data.msg)
          //       this.loginLoading = false
          //     }
          //   })
          //   .catch((_err) => {
          //     this.$message.error('服务器连接失败，请稍后重试......')
          //     this.loginLoading = false
          //   })
        } else {
          return false
        }
      })
    }
  }
}
</script>

<style scoped lang='scss'>
.login {
  width: 100%;
  height: 100%;
  background-image: url('../assets/img/bg.jpg');
  position: absolute;
  left: 0;
  top: 0;
  background-size: 100% 100%;
}

.login-card {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  margin: auto;
  width: 20%;
  min-width: 380px;
  height: 500px;
  min-height: 500px;
  border-radius: 10px;
  text-align: center;
}

.login-image {
  width: 60px;
  height: 60px;
  margin-top: 40px;
}

.login-title {
  font-size: 25px;
  font-weight: bold;
}

.login-desc {
  letter-spacing: 2px;
  color: #99999a;
}

.el-button {
  width: 100%;
  height: 40px;
}
.footer{
  position: absolute;
left: 50%;
bottom: 0;
transform: translate(-50%,0);
color: #ffffff;
}
.input{
  height: 40px;
}
</style>
